package gold.contest;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC6077 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {

        int factor = 1000000007;

        public int totalStrength(int[] strength) {
            int n = strength.length;
            long ans = 0L;
            for (int i = 0; i < n; i++) {
                long cur = 0L, sum = 0L, min = strength[i];
                for (int j = i; j >= 0; j--) {
                    sum += strength[j];
                    min = Math.min(min, strength[j]);
                    cur = (cur + sum * min) % factor;
                }
                ans = (ans + cur) % factor;
            }

            return (int) ans;
        }
    }

    public void run() {
        System.out.println(new Solution().totalStrength(InputUtil.toIntegerArray("[1,3,1,2]")));
        System.out.println(new Solution().totalStrength(InputUtil.toIntegerArray("[5,4,6]")));
    }

    public static void main(String[] args) throws Exception {
        LC6077 an = new LC6077();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
